package com.onelap.bls.treadmillcalibration.utils;

import android.app.Activity;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.PermissionUtils;
import com.blankj.utilcode.util.ScreenUtils;

import java.util.List;

public class PermissionUtil {

    /**
     * 申请权限
     *
     * @param permissions 所需权限
     */
    public static void applyForPermission(final String[] permissions) {
        LogUtils.i("222222222222");
        PermissionUtils.permission(permissions)
                .rationale(new PermissionUtils.OnRationaleListener() {
                    @Override
                    public void rationale(final ShouldRequest shouldRequest) {
                        LogUtils.i("333333333333");
                        DialogHelper.showRationaleDialog(shouldRequest);
                    }
                })
                .callback(new PermissionUtils.FullCallback() {
                    @Override
                    public void onGranted(List<String> permissionsGranted) {
                        LogUtils.i("4444444444444444");
                    }

                    @Override
                    public void onDenied(List<String> permissionsDeniedForever, List<String> permissionsDenied) {
                        LogUtils.i("5555555555555");
                        if (!permissionsDeniedForever.isEmpty())
                            DialogHelper.showOpenAppSettingDialog();
                        else PermissionUtil.applyForPermission(permissions);
                    }
                })
                .theme(new PermissionUtils.ThemeCallback() {
                    @Override
                    public void onActivityCreate(Activity activity) {
                        ScreenUtils.setFullScreen(activity);
                    }
                })
                .request();
    }
}
